package com.itheima.controller;

import com.itheima.pojo.Movie_Counts;
import com.itheima.pojo.Movie_Info;
import com.itheima.service.Movie_InfoService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

@Controller
public class MovieController {
    @Autowired
    @Qualifier("movieInfoService")
    Movie_InfoService movie_infoService;
@RequestMapping("/movie1")
@ResponseBody
    public List<String> Movie1(){
    List<Movie_Counts> moviesByMovieCounts = movie_infoService.getMoviesByMovieCounts();
    ArrayList<String> namelist= new ArrayList<>();
    for (Movie_Counts mo:moviesByMovieCounts
         ) {
        namelist.add(mo.getName());
    }
    return namelist;
}
    @RequestMapping("/movie2")
    @ResponseBody
    public List<Integer> Movie2(){
        List<Movie_Info> moviesByMovieYeas = movie_infoService.getMoviesByMovieYeas();
        ArrayList<Integer> arrayList = new ArrayList<>();
        for (Movie_Info a:moviesByMovieYeas
             ) {
            arrayList.add(a.getMovie_year());
        }
        return arrayList;
    }
    @RequestMapping(value = "/movie3", method = RequestMethod.GET, produces = {"application/json;charset=UTF-8"})
    @ResponseBody
    public List<Movie_Info> Movie3(@Param("type") String type, @Param("year")Integer year, @Param("keyword")String keyword){
//        System.out.println(type+year+keyword);
//    return null;
        List<Movie_Info> moviesInfoByKeyWords = movie_infoService.getMoviesInfoByKeyWords(type, year, keyword);
        return moviesInfoByKeyWords;
    }
    @RequestMapping("/movietest")
    public String test(){
        return "test";
    }
}
